package marketplace.componente.carrocompras;

import java.io.Serializable;
import java.util.ArrayList;

import javax.ejb.EJB;
import javax.ejb.Remove;
import javax.ejb.Stateful;


import marketplace.componente.transacciones.SistemaTransaccionesRemote;

import marketplace.objects.TransaccionBO;


//java:global/EnterpriseMarketplaceProject/ComponenteCarroCompras/CarroCompras
/**
 * Session Bean implementation class CarroCompras
 */
@Stateful
public class CarroCompras implements CarroComprasRemote{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@EJB
	private SistemaTransaccionesRemote sistTrans;
	
	private ArrayList<TransaccionBO> carrito = new ArrayList<TransaccionBO>();
	
	private double valorTotal = 0;

    /**
     * Default constructor. 
     */
    public CarroCompras() {
        // TODO Auto-generated constructor stub
    }

	@Override
	public void agregarAlCarrito(TransaccionBO elementoTransaccion) {
		// TODO Auto-generated method stub
		carrito.add(elementoTransaccion);
		
	}

	@Override
	public void eliminarDelCarrito(TransaccionBO servicioAEliminar) {
		// TODO Auto-generated method stub
		carrito.remove(servicioAEliminar);
	}

	@Override
	public ArrayList<TransaccionBO> darElementosDelCarrito() {
		// TODO Auto-generated method stub
		return carrito;
	}

	@Override
	public double darValorTotalDelCarrito() {
		// TODO Auto-generated method stub
				
		for(TransaccionBO t:carrito){
			valorTotal += t.getValorTotal();
		}
		
		return valorTotal;
	}

	@Override
	@Remove
	public void efectuarCompra() {
		// TODO Auto-generated method stub
		sistTrans.registrarTransacciones(carrito);
	}

}
